import { Component, Vue, Inject } from 'vue-property-decorator';

import { IRoomGoods } from '@/shared/model/room-goods.model';
import RoomGoodsService from './room-goods.service';
import AlertService from '@/shared/alert/alert.service';

@Component
export default class RoomGoodsDetails extends Vue {
  @Inject('roomGoodsService') private roomGoodsService: () => RoomGoodsService;
  @Inject('alertService') private alertService: () => AlertService;

  public roomGoods: IRoomGoods = {};

  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (to.params.roomGoodsId) {
        vm.retrieveRoomGoods(to.params.roomGoodsId);
      }
    });
  }

  public retrieveRoomGoods(roomGoodsId) {
    this.roomGoodsService()
      .find(roomGoodsId)
      .then(res => {
        this.roomGoods = res;
      })
      .catch(error => {
        this.alertService().showHttpError(this, error.response);
      });
  }

  public previousState() {
    this.$router.go(-1);
  }
}
